<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../vue.js"></script>
    <script src="../node_modules/_jquery@3.3.1@jquery/dist/jquery.min.js"></script>
    <script src="../node_modules/_bootstrap@3.3.7@bootstrap/dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../node_modules/_bootstrap@3.3.7@bootstrap/dist/css/bootstrap.min.css">
</head>

<body>
    <div id="app">
        id:<input type="text" v-model="m1"> name:
        <input type="text" v-model="m2" @keyup.enter="add" v-color>
        <button @click="add">添加</button>
        <input type="text" v-model="m3"> <button @click="search">搜索</button>
        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading">Panel heading</div>

            <!-- Table -->
            <table class="table">
                <thead>
                    <th>
                        <td>id</td>
                        <td>name</td>
                        <td>ctime</td>
                        <td>delit</td>
                    </th>
                </thead>
                <tbody>
                    <tr v-for="item in list">
                        <td></td>
                        <td>{{item.id}}</td>
                        <td>{{item.name}}</td>
                        <td>{{item.ctime|timepage}}</td>
                        <td>
                            <a href="#" @click.prevent="del(item.id)">{{item.delit}}</a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>


    </div>
    <script src="../node_modules/_moment@2.23.0@moment/min/moment.min.js"></script>
    <script>
        Vue.filter("timepage", function(data) {
            return moment(data).format("YYYY-MM-DD hh:mm:ss");

        })

        // Vue.directive("color", {
        //     bind: function(el) {
        //         el.style.color = "skyblue"
        //     }
        // })

        new Vue({
            el: "#app",
            data: {
                m1: "",
                m2: "",
                m3: "",
                list: [{
                    id: 1,
                    name: "宝马",
                    ctime: new Date(),
                    delit: "删除"
                }, {
                    id: 2,
                    name: "奔驰",
                    ctime: new Date(),
                    delit: "删除"
                }]
            },
            methods: {
                search() {
                    if (this.m3 == list.name) {

                    }
                },
                add() {
                    this.list.push({
                        id: this.m1,
                        name: this.m2,
                        ctime: new Date(),
                        delit: "删除"
                    })
                    this.m1 = ""
                    this.m2 = ""
                },
                del(id) {
                    this.list.splice(this.list.findIndex(item => item.id = id), 1)
                }

            }
        })
    </script>
</body>

</html>